package org.timeismoney.payment.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.timeismoney.payment.model.SchoolYear;
import org.timeismoney.payment.service.SchoolYearService;
import org.timeismoney.payment.web.WebUtils;

public class SchoolYearAction extends BaseAction {
	private static Logger		log	= Logger.getLogger(SchoolYearAction.class);
	private SchoolYearService	service;

	public void setService(SchoolYearService service) {
		this.service = service;
	}
	
	public ActionForward get(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		try {
			List<SchoolYear> years = service.getAll();
			renderJson(response, SchoolYear.toJson(years));
		} catch (Exception e) {
			log.error(e.getMessage());
			renderJson(response, WebUtils.generateErrorJSON(TEXT_ERROR_MSG_QUERY+" "+e.getMessage()));
		}
		return null;
	}

}
